$(function () {
    $.ajax({
        url: "/api/permission/findSysPermissionByUserId",
        dataType: "json",
        success: function (data) {
            menuInit(data.data);
        }
    });
});


function menuInit(menuJson) {
    var menu = null;
    var html = null;
    var chidLen = null;
    var child = null;
    for (var i = 0; i < menuJson.length; i++) {
        menu = menuJson[i];
        if(i==0){
            html = $(' <li menu-id="' + i + '" class="active treeview "><li>');
        }else{
            html = $(' <li menu-id="' + i + '" class="treeview "><li>');
        }

        $(".sidebar .sidebar-menu").append(html);

        html = $(' <a href="'+menu.url+'"> <i class="fa fa-dashboard"></i> <span>'+menu.name+'</span> <span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i> </span> </a> <ul menuUl-id="'+i+'" class="treeview-menu"> </ul>');
        $('[menu-id="'+i+'"]').append(html);

        chidLen = menu.children.length;
        if(chidLen>0){
            for (var j = 0; j <= chidLen; j++) {
                child = menu.children[j];
                if (j == 0 && i==0) {
                    html = $('<li class="active"><a href="javascript:void(0);" menu-controller="' + child.url + '"><i class="fa fa-circle-o"></i> ' + child.name + '</a></li>');
                } else {
                    html = $('<li class=""><a href="javascript:void(0);" menu-controller="' + child.url + '"><i class="fa fa-circle-o"></i> ' + child.name + '</a></li>');
                }

                $('[menuUl-id="' + i + '"]').append(html);
            }
        }
    }

    $('.sidebar-menu').append(html);
    /*$(Selector.data).each(function () {
        Plugin.call($(this))
    })*/
    //$(".sidebar-menu li:first ul li:first a").click();
}